<template>
  <div class="home">
    <!-- 顶部轮播图 -->
    <el-carousel height="200px" class="banner">
      <el-carousel-item>
        <div class="banner-content">
          <h2>常州新政补贴新房一览表</h2>
          <p>小牛看房专属额外最高19%补贴 领跑全城</p>
        </div>
      </el-carousel-item>
      <!-- 其他轮播项... -->
    </el-carousel>

    <!-- 房源类型区域 -->
    <div class="house-types">
      <div class="type-item" @click="goToList('rent')">
        <div class="icon-wrapper">
          <el-icon><House /></el-icon>
        </div>
        <span>租房</span>
      </div>
      <div class="type-item" @click="goToList('xiaoniugongyu')">
        <div class="icon-wrapper">
          <el-icon><Office /></el-icon>
        </div>
        <span>小牛公寓</span>
      </div>
      <div class="type-item" @click="goToList('new')">
        <div class="icon-wrapper">
          <el-icon><HomeFilled /></el-icon>
        </div>
        <span>新房</span>
      </div>
      <div class="type-item" @click="goToList('second')">
        <div class="icon-wrapper">
          <el-icon><House /></el-icon>
        </div>
        <span>二手房</span>
      </div>
    </div>

    <!-- 找房方式区域 -->
    <div class="search-methods">
      <div class="method-item" @click="goToSearch('deal')">
        <div class="icon-box">
          <el-icon><Money /></el-icon>
        </div>
        <span>查成交</span>
      </div>
      <div class="method-item" @click="goToMap('bus')">
        <div class="icon-box">
          <el-icon><Van /></el-icon>
        </div>
        <span>公交找房</span>
      </div>
      <div class="method-item" @click="goToMap('community')">
        <div class="icon-box">
          <el-icon><Location /></el-icon>
        </div>
        <span>找小区</span>
      </div>
      <div class="method-item" @click="goToMap('school')">
        <div class="icon-box">
          <el-icon><School /></el-icon>
        </div>
        <span>学校找房</span>
      </div>
      <div class="method-item" @click="goToSearch('help')">
        <div class="icon-box">
          <el-icon><Search /></el-icon>
        </div>
        <span>帮我找房</span>
      </div>
    </div>

    <!-- 发布房源区域 -->
    <div class="publish-section">
      <div class="publish-item" @click="goToPublish('add')">
        <el-icon><Plus /></el-icon>
        <div class="publish-content">
          <div class="title">添加房产</div>
          <div class="desc">房屋估价</div>
        </div>
      </div>
      <div class="publish-item" @click="goToPublish('sell')">
        <el-icon><Sell /></el-icon>
        <div class="publish-content">
          <div class="title">我要出售</div>
          <div class="desc">发布房源</div>
        </div>
      </div>
      <div class="publish-item" @click="goToPublish('rent')">
        <el-icon><Upload /></el-icon>
        <div class="publish-content">
          <div class="title">我要出租</div>
          <div class="desc">出租房源</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import {
  House,
  Office,
  HomeFilled,
  Money,
  Van,
  Location,
  School,
  Search,
  Plus,
  Sell,
  Upload
} from '@element-plus/icons-vue'

const router = useRouter()

// 跳转到房源列表
const goToList = (type) => {
  router.push({
    name: 'HouseList',
    query: { type }
  })
}

// 跳转到地图找房
const goToMap = (type) => {
  router.push({
    name: 'MapSearch',
    query: { type }
  })
}

// 跳转到搜索页面
const goToSearch = (type) => {
  router.push({
    name: 'Search',
    query: { type }
  })
}

// 跳转到发布页面
const goToPublish = (type) => {
  router.push({
    name: 'Publish',
    query: { type }
  })
}
</script>

<style scoped>
.home {
  background: #f5f5f5;
  min-height: 100vh;
}

.banner {
  margin-bottom: 20px;
}

.banner-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.3)), url('/banner-bg.jpg');
  background-size: cover;
}

.house-types {
  background: white;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.type-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.icon-wrapper {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #f0f9ff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-methods {
  background: white;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.method-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 10px;
  border-radius: 8px;
  transition: all 0.3s;
}

.method-item:hover {
  background: #f5f7fa;
}

.icon-box {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ecf5ff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #409EFF;
}

.publish-section {
  background: white;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.publish-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.publish-item:hover {
  background: #f5f7fa;
}

.publish-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.publish-content .title {
  font-weight: bold;
}

.publish-content .desc {
  font-size: 12px;
  color: #999;
}

.el-icon {
  font-size: 24px;
}
</style> 